<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- 
功能介绍：模版添加

 -->
<%@ include file="/files/db/conn.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" rev="stylesheet" href="css/style.css" type="text/css" media="all" />
<script type="text/javascript" src="<%=path %>/files/crypto/sm4-1.0.js"></script>
 
    <script type="text/javascript" src="<%=path %>/files/utils/hex.js"></script>
    <script type="text/javascript" src="<%=path %>/files/utils/byteUtil.js"></script>
    
<style type="text/css">
<!--
.atten {font-size:12px;font-weight:normal;color:#F00;}
-->
</style>
<%
if(request.getParameter("flag")!=null&&"success".equals(request.getParameter("flag"))){
	response.getWriter().println("<script>alert('添加成功!');</script>");
}
%>
<script type="text/javascript">
		function checkValue(){
				if(document.form.title.value==""||document.form.title.value==null)
				{
					alert("不能为空！");
					document.form.title.focus();
					return false;
				}
				if(document.form2.file.value.replace(/[ ]/g,"")==""){
					 alert("请选择文件!");
					 return false;
				}
				var i;
				
             var form7 = document.getElementById("form1217");
             
        //var publicKeyHex = "04c12b414c3b1183cd0305da0f54a4aaf7e27e5cd1d1d9360b46dd852a58fdb6d2ddea673cf7c4bc36211d03b04b2c8bcb5b15d745453cee635ed6e895c5c5ada0";
        var sm4key = '';
        for (i = 0; i < 32; i++) {
            sm4key += Math.floor(Math.random() * 16).toString(16)
        }
        sm4key = sm4key.toLowerCase();
        
        var sm4iv = '';
        for (i = 0; i < 32; i++) {
            sm4iv += Math.floor(Math.random() * 16).toString(16)
        }
        sm4iv = sm4iv.toLowerCase();
        document.form.sm4key.value = sm4key;
        document.form.sm4iv.value = sm4iv;
        var titleValue = form7.elements["title"].value;
        var titleBytes = Hex.utf8StrToBytes(titleValue);
        var remarkValue = form7.elements["remark"].value;
        var remarkBytes = Hex.utf8StrToBytes(remarkValue);
        var touserValue = form7.elements["touser"].value;
        var touserBytes = Hex.utf8StrToBytes(touserValue);
        var typeidValue = form7.elements["typeid"].value;
        var typeidBytes = Hex.utf8StrToBytes(typeidValue);
        //alert(touserValue);
        
        var sm4keyHex = Hex.decode(sm4key);
        var sm4ivHex = Hex.decode(sm4iv);
        var sm4 = new SM4();
        
        var titleEncryptedHex = sm4.encrypt_cbc(sm4keyHex, sm4ivHex, titleBytes);
        var titleEncrypted = Hex.encode(titleEncryptedHex, 0, titleEncryptedHex.length).toLowerCase();
        form7.title.value = titleEncrypted;
        
        var remarkEncryptedHex = sm4.encrypt_cbc(sm4keyHex, sm4ivHex, remarkBytes);
        var remarkEncrypted = Hex.encode(remarkEncryptedHex, 0, remarkEncryptedHex.length).toLowerCase();
        form7.remark.value = remarkEncrypted;
        
        var touserEncryptedHex = sm4.encrypt_cbc(sm4keyHex, sm4ivHex, touserBytes);
        var touserEncrypted = Hex.encode(touserEncryptedHex, 0, touserEncryptedHex.length).toLowerCase();
        form7.jieshouzhe.value = touserEncrypted;
        //alert(form7.jieshouzhe.value);
        var typeidEncryptedHex = sm4.encrypt_cbc(sm4keyHex, sm4ivHex, typeidBytes);
        var typeidEncrypted = Hex.encode(typeidEncryptedHex, 0, typeidEncryptedHex.length).toLowerCase();
        form7.wenjianleixing.value = typeidEncrypted;
        alert(form7.wenjianleixing.value);
        
    
       form7.submit();
		}
		function Upload(){
			if(document.form2.file.value.replace(/[ ]/g,"")==""){
			 alert("请选择文件!");
			}else{
				document.form2.action="/fileweb/files/file/upload.jsp";
				document.form2.target="_blank";
				document.form2.submit();
			}
	   }
</script>
</head>

<body class="ContentBody">
  <form action="files/file/addDao.jsp" method="post"  id ="form1217" name="form" >
<div class="MainDiv">
<table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">
   <tr>
      <td height="10">&nbsp;</td>
  </tr>
  <tr>
      <td align="left" ><font color="blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;发送文件>>添加</font></td>
  </tr>
  <tr>
    <td class="CPanel">		
		<table border="0" cellpadding="0" cellspacing="0" style="width:100%">		
		<tr>
			<td width="100%">
				<fieldset style="height:100%;">
				<legend>文件</legend>
					  <table border="0" cellpadding="2" cellspacing="1" style="width:100%">
					  <tr>
					    <td align="right" width="19%">标题:</td>
					    <td width="35%"><span class="red">
				        <input name='title' type="text" class="text" style="width:354px" value=""/>
				        <input name='fileName' id="fileName" type="hidden" />
				        *</span>
				        </td>
					  </tr>
					  <tr>
					    <td align="right" width="19%">备注:</td>
					    <td width="35%"><span class="red">
					    <textarea name='remark' rows="4" cols="60"></textarea>
				        *</span>
				        </td>
					  </tr>
					  <tr>
					    <td align="right" width="19%">收件人:</td>
					    <td width="35%"><span class="red">
					    <select name='touser' >
						<%
						ResultSet rs = null;
							String sql = "select * from t_user where role =2";
							rs = stmt.executeQuery(sql);
						while(rs.next()) {
						%>
						<option  value="<%=rs.getString("id") %>" ><%=rs.getString("realname") %> </option>
					     	<%
						} 
						%>   
						</select>
				        *</span>
				        </td>
					  </tr>
					  <tr>
					    <td align="right" width="19%">文件类型:</td>
					    <td width="35%"><span class="red">
					    <select name='typeid' >
						<%
						stmt1 = conn.createStatement();
						ResultSet rs1 = null;
							String sql1 = "select * from t_filetype";
							rs1 = stmt1.executeQuery(sql1);
						while(rs1.next()) {
						%>
						<option value="<%=rs1.getString("id") %>" ><%=rs1.getString("typename") %> </option>
					     	<%
						} 
						%>   
						</select>
				        *</span>
				        </td>
					  </tr>
					  </form>
					 <form method="post" name="form2" id="form2" enctype="multipart/form-data" >
					  <tr>
					    <td align="right" width="19%">上传附件:</td>
					    <td width="35%"><span class="red">
				        
				        <input name="file" type="file" class="Style_upload" id="file">
				        <input type="button" name="Submit2" value="上传" onClick="Upload()">
				        </span>
				        </td>
					  </tr>
			
					  </form>
					  </table>
			  <br />
				</fieldset>			</td>
			
		</TR>
		
		
		
		</TABLE>
	
	
	 </td>
  </tr>
  
		 <tr>
                <td>
                    <input type="hidden" name="sm4key">
                </td>
            </tr>
            <tr>
                <td>
                    <input type="hidden" name="sm4iv">
                </td>
            </tr>
            <tr>
                <td>
                    <input type="hidden" name="jieshouzhe">
                </td>
            </tr>
            <tr>
                <td>
                    <input type="hidden" name="wenjianleixing">
                </td>
            </tr>
            
		<TR>
			<TD colspan="2" align="center" height="50px">
			<input type="button" name="submitbut" value="保存" class="button"  onClick="return checkValue()" />　
			
			<input type="reset" name="reset" value="重置" class="button"  /></TD>
		</TR>
		</TABLE>
</div>

</body>
</html>
